package com.jrx.anytxn.transaction.job.marketingFile.step;

import com.jrx.anytxn.transaction.config.MarketingFileConfig;
import com.jrx.anytxn.transaction.constant.TransBizConstant;
import com.jrx.anytxn.transaction.service.IMarketingFileService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MarketingSumFileWriter implements ItemWriter<String> {

    @Autowired
    private IMarketingFileService marketingFileService;

    @Autowired
    private MarketingFileConfig marketingFileConfig;

    @Override
    public void write(List<? extends String> items) throws Exception {
        if(CollectionUtils.isNotEmpty(items)){
            marketingFileService.generatingFile((List<String>) items,marketingFileConfig.getMarketingFilePath(),
                    marketingFileConfig.getMarketingFileName(), TransBizConstant.FILE_NAME_MARKET_SUM);
        }
    }
}
